package com.springCloud.factory;

/**
 * @ClassName Factory
 * @Author 1628994918qq.com
 * @Date 2023/3/31 16:34
 * 工厂模式
 */
public class Factory {
    public Product createProduct(String type) {
        if (type.equals("A")) {
            return new CreateProductAImpl();
        } else if (type.equals("B")) {
            return new CreateProductBImpl();
        } else {
            throw new IllegalArgumentException("无法创建该类型的产品");
        }
    }

    public static void main(String[] args) {
        Factory factory = new Factory();

        // 创建产品A
        Product productA = factory.createProduct("A");
        productA.use();

        // 创建产品B
        Product productB = factory.createProduct("B");
        productB.use();
    }
}
